/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mapbox.ohos.gestures;

/**
 * Class that holds initial, previous and current X and Y on-screen coordinates for active pointers.
 */
public final class MoveDistancesObject {
    private final float initialX;
    private final float initialY;

    private float prevX;
    private float prevY;
    private float currX;
    private float currY;

    private float distanceXSinceLast;
    private float distanceYSinceLast;
    private float distanceXSinceStart;
    private float distanceYSinceStart;

    /**
     * MoveDistancesObject
     *
     * @param initialX
     * @param initialY
     */
    public MoveDistancesObject(float initialX, float initialY) {
        this.initialX = initialX;
        this.initialY = initialY;
    }

    /**
     * Add a new position of this pointer and recalculate distances.
     *
     * @param pX new X coordinate
     * @param pY new Y coordinate
     */
    public void addNewPosition(float pX, float pY) {
        prevX = currX;
        prevY = currY;

        currX = pX;
        currY = pY;

        distanceXSinceLast = prevX - currX;
        distanceYSinceLast = prevY - currY;

        distanceXSinceStart = initialX - currX;
        distanceYSinceStart = initialY - currY;
    }

    /**
     * Get X coordinate of this pointer when it was first register.
     *
     * @return X coordinate
     */
    public float getInitialX() {
        return initialX;
    }

    /**
     * Get Y coordinate of this pointer when it was first register.
     *
     * @return Y coordinate
     */
    public float getInitialY() {
        return initialY;
    }

    /**
     * Get previous X coordinate of this pointer.
     *
     * @return X coordinate
     */
    public float getPreviousX() {
        return prevX;
    }

    /**
     * Get previous Y coordinate of this pointer.
     *
     * @return Y coordinate
     */
    public float getPreviousY() {
        return prevY;
    }

    /**
     * Get current X coordinate of this pointer.
     *
     * @return X coordinate
     */
    public float getCurrentX() {
        return currX;
    }

    /**
     * Get current Y coordinate of this pointer.
     *
     * @return Y coordinate
     */
    public float getCurrentY() {
        return currY;
    }

    /**
     * Get X distance covered by this pointer since previous position.
     *
     * @return X distance
     */
    public float getDistanceXSinceLast() {
        return distanceXSinceLast;
    }

    /**
     * Get Y distance covered by this pointer since previous position.
     *
     * @return Y distance
     */
    public float getDistanceYSinceLast() {
        return distanceYSinceLast;
    }

    /**
     * Get X distance covered by this pointer since start position.
     *
     * @return X distance
     */
    public float getDistanceXSinceStart() {
        return distanceXSinceStart;
    }

    /**
     * Get Y distance covered by this pointer since start position.
     *
     * @return Y distance
     */
    public float getDistanceYSinceStart() {
        return distanceYSinceStart;
    }
}

